package org.wlw.ex;

public class TestException01 {

	public static void main(String[] args) {
		try {
			System.out.println("程序开始");
			int a = 10;
			int b = 0;
			int ans = divide(a,b);
			System.out.println(ans);
			System.out.println("程序结束");
		} catch(ArithmeticException e) {
			System.out.println("main:"+e.getMessage());
		}
		
	}
	
	public static int divide(int a,int b) {
		int n = 0;
		try {
			System.out.println("准备除法");
			n = a/b;
			System.out.println("除法完成");
		} catch(ArithmeticException e) {
			System.out.println(e.getMessage());
			//如果希望异常被上一级所处理，可以继续把异常向上抛出，使用throw关键字抛出
			//throw后面抛出的是对象
			throw e;
		}
		return n;
	}

}
